package server;

import java.io.File;
import java.io.FileNotFoundException;

import util.Logger;

import dataContracts.FileStatus;
import dataContracts.SharedDirectory;
import dataContracts.SharedFile;

public class ServerDirectory extends SharedDirectory {

	public ServerDirectory(String directoryPath) {
		super(directoryPath);
		
		loadFiles();
	}
	
	public void loadFiles() {
		files.clear();
		
		if (directory.isDirectory()) {
	    	for (File f : directory.listFiles()) {
	    		if (!f.isHidden())
	    			this.files.add(new SharedFile(f));
			}
    	}
		
		updateDirectoryChecksum();
	}
	
// METHODS FOR ADDING FILES TO THE COLLECTION 
	
	public void addFile(SharedFile file) {
		files.add(file);
		Logger.Debug("Added file to collection: "+ file.getName() + " ("+ files.size() +" total)");
	}
	
	public void addFile(String fileName) {
		SharedFile sf = new SharedFile(new File(fileName));
		addFile(sf);
	}
}
